package task01;

import java.io.Serializable;

public class Student implements Serializable {

    private static final long serialVersionUID = 7703586480175043754L;
    private String id;  //学号
    private String name;  //名字
    private Gender gender;  //性别
    private int age;  //年龄
    private int grade;  //班级

    public enum Gender{ MALE, FEMALE };

    public Student(String id, String name, String gender, int age, int grade) throws AgeException, GenderException, GradeException {
        setId(id);
        setName(name);
        setAge(age);
        setGender(gender);
        setGrade(grade);

    }

    public Student() {
    }

    public int getAge() {
        return age;
    }

    public int getGrade() {
        return grade;
    }

    public String getGender() {
        if(this.gender.equals(Gender.FEMALE))
            return "女";
        else if (this.gender.equals(Gender.MALE))
            return "男";
        else return "";
    }

    public String getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setAge(int age) throws AgeException {

        if(age<100 && age>0)
            this.age = age;
        else
           throw new AgeException();

    }

    public void setGender(String gender) throws GenderException {

        if(gender.equals("男"))
            this.gender = Gender.MALE;
        else if(gender.equals("女"))
            this.gender = Gender.FEMALE;
        else
            throw new GenderException();
    }

    public void setGrade(int grade) throws GradeException {
        if (grade>=0 && grade<=100)
            this.grade = grade;
        else
            throw new GradeException();
    }

    public void setId(String id) {
        this.id = id;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id='" + getId() + '\'' +
                ", name='" + getName() + '\'' +
                ", gender='" + getGender() + '\'' +
                ", age=" + getAge() +
                ", grade=" + getGrade() +
                '}';
    }
}
